﻿using PosClient.Helper;
using PosClient.Interfaces;
using PosClient.Model;
using PosClient.ViewModel;
using Splat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Text;
using System.Threading.Tasks;

namespace PosClient.Job.DownLoad
{
    public class GoodDownLoadJob:IJob
    {
        public Result<JobEntity> Excute()
        {
            Result<JobEntity> result = new Result<JobEntity>()
            {
                Success = true,
                Message = "Good请求成功"
            };
            var viewModel = Locator.Current.GetService<MainViewModel>();
            viewModel._mainScheduler.Schedule(() =>
            {
                viewModel.SubText = "正在下载商品数据...";
                viewModel.Loading = true;
            });
            var cache = Locator.Current.GetService<IPluService>();
            List<Plu> pluList = new List<Plu>();
            pluList.Add(new Plu() 
            {
                PluId = 0,
                PluCode = "0002818",
                PluName = "海象奶砖(奶油)升级版",
                PluImage = null,
                PluSvg = "",
                Price = 5.9m,
                Count = 1,
                CanDiscount = "1",
                Tag = Plu.PluTag.Normal,
                Amount = 0,
                OriginAmount = 0,
                OriginPrice = 0,
                VipPrice = 0,
                Barcode = "259451651812",
                DisAmount = 0,
                TagList = new List<string> { "买一送一", "限时特价", "组合价" }
            });
            pluList.Add(new Plu()
            {
                PluId = 0,
                PluCode = "0002817",
                PluName = "欧特家博士融情意馆四种奶酪比萨",
                PluImage = null,
                PluSvg = "",
                Price = 5.9m,
                Count = 1,
                CanDiscount = "0",
                Tag = Plu.PluTag.Normal,
                Amount = 0,
                OriginAmount = 0,
                OriginPrice = 0,
                VipPrice = 0,
                Barcode = "569451651812",
                DisAmount = 0,
                TagList = new List<string>()
            });
            pluList.Add(new Plu()
            {
                PluId = 0,
                PluCode = "0002816",
                PluName = "典藏西拉红葡萄酒",
                PluImage = null,
                PluSvg = "",
                Price = 5.9m,
                Count = 1,
                CanDiscount = "1",
                Tag = Plu.PluTag.Normal,
                Amount = 0,
                OriginAmount = 0,
                OriginPrice = 0,
                VipPrice = 0,
                Barcode = "599451651892",
                DisAmount = 0,
                TagList = new List<string> { "换购" }
            });
            cache.CachePlu(pluList);
            viewModel._mainScheduler.Schedule(() =>
            {
                viewModel.SubText = string.Empty;
                viewModel.Loading = false;
            });
            return result;
        }
    }
}
